x = int(input())

for _ in range(x):
    n = int(input())
    data = []
    for _ in range(n):
        data+=list(map(int,input()))

    cnt = data.count(1)
    if cnt > n / 2:
        print(n*2-1)
    else:
        print(cnt)
